﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using NHibernate.Cfg.MappingSchema;

namespace MVCGen.Generators.Entity {
	public class HbmBagFieldGenerator : ICodeTypeMemberGenerator {
		private HbmBag bag;
		private ICodeTypeMemberGenerator elementGenerator;

		public HbmBagFieldGenerator(HbmBag bag) {
			this.bag = bag;
			if (bag.Item1 is HbmElement)
				this.elementGenerator = new HbmElementFieldGenerator(bag.name, bag.Item1 as HbmElement);
			else if (bag.Item1 is HbmManyToMany)
				this.elementGenerator = new HbmManyToManyFieldGenerator(bag.name, bag.Item1 as HbmManyToMany);
			else if (bag.Item1 is HbmCompositeElement)
				this.elementGenerator = new HbmCompositeElementFieldGenerator(bag.name, bag.Item1 as HbmCompositeElement);
			else if (bag.Item1 is HbmManyToAny)
				this.elementGenerator = new HbmManyToAnyFieldGenerator(bag.name, bag.Item1 as HbmManyToAny);
			else if (bag.Item1 is HbmOneToMany)
				this.elementGenerator = new HbmOneToManyFieldGenerator(bag.name, bag.Item1 as HbmOneToMany);
			else
				throw new ArgumentException(String.Format("Unsupported bag item {0}", bag.Item1.GetType().Name));
		}

		public CodeTypeMember Generate() {
			return elementGenerator.Generate();
		}
	}
}
